function [dresults, dflags] = estimate_demand( ...
    Pi,        ...
    rho,       ...
    df,        ...
    dfull,     ...
    price_iv,  ...
    model,     ...
    par_rest,  ...
    coefs_sim, ...
    tolerance  ...
)

    [xlinear, ~, xnonlin, fe, ~, zdemand, ~, zinside, ~] = final_variables(df, price_iv, model);
    s_jt     = df.s_jt;
    p_jt     = df.p_jt;
    prodid   = df.prodid;
    market   = df.cdid;
    cluster  = df.cdid;
    dresults = struct;

    varargin = {};

    try
        dresults = estimate_rcnl(   ...
                Pi,          ...
                rho,         ...
                s_jt,        ...
                p_jt,        ...
                prodid,      ...
                xlinear,     ...
                xnonlin,     ...
                zdemand,     ...
                zinside,     ...
                fe,          ...
                market,      ...
                dfull,       ...
                cluster,     ...
                model,       ...
                par_rest,    ...
                coefs_sim,   ...
                tolerance,   ...
                varargin{:});
        dflags = 0
    catch err
        fprintf('%s: %s\n', err.identifier, err.message);
        dflags = 1
    end


end
